package com.yanqu.road.server.cmd.activity.ruishou;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.RuiShouProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ruishou.RuiShouModule;
import com.yanqu.road.server.pb.RuiShouPb;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = RuiShouProto.RuiShouShootReqMsg.class, respMsg = RuiShouProto.RuiShouShootRespMsg.class)
@Cmd(code = Protocol.S_RUI_SHOU_SHOOT, desc = "发射")
public class RuiShouShootCmd extends AbstractCommand {

    private int areaId;

    private int times;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        RuiShouProto.RuiShouShootReqMsg reqMsg = RuiShouProto.RuiShouShootReqMsg.parseFrom(packet.getBytes());
        areaId = reqMsg.getArea();
        times = reqMsg.getCnt();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(RuiShouModule.class).shoot(areaId, times);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            RuiShouProto.RuiShouShootRespMsg.Builder respMsg = RuiShouProto.RuiShouShootRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_RUI_SHOU_SHOOT, respMsg);
        }
    }
}
